package com.fantastic.web.controller.admin;

import com.fantastic.common.exception.enums.RespStatusInfo;
import com.fantastic.common.result.ResultData;
import com.fantastic.model.pojo.zjs.Integral;
import com.fantastic.service.zjs.IntegralService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: rxx
 * @since: 2024/6/4 09:36
 * @description: 积分商城信息表请求控制器
 */
@RestController
@RequestMapping("/integral")
public class IntegralControllerAdmin {

    @Resource
    private IntegralService integralService;

    /**
     * 查询积分商城信息
     *
     * @param integral
     * @param pageSize
     * @param pageNum
     * @return
     */
    @GetMapping("/listIntegral")
    public ResultData listIntegral(Integral integral,
                                   @RequestParam(name="page",
                                           defaultValue = "1") int pageNum,
                                   @RequestParam(name="limit",defaultValue = "9999999") int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Integral> integrals = integralService.listIntegral(integral);
        PageInfo<Integral> pageInfo = new PageInfo<>(integrals);
        return new ResultData(RespStatusInfo.OK, pageInfo);
    }

    /**
     * 查询单个积分商城信息
     *
     * @param integralId
     * @return
     */
    @GetMapping("/getIntegral")
    public ResultData getIntegral(Integer integralId) {
        return new ResultData(RespStatusInfo.OK, integralService.getIntegral(integralId));
    }

    /**
     * 添加积分商城信息
     *
     * @param integral
     * @return
     */
    @PostMapping("/insertIntegral")
    public ResultData insertIntegral(Integral integral) {
        return new ResultData(RespStatusInfo.OK, integralService.insertIntegral(integral));
    }

    /**
     * 修改积分商城信息
     *
     * @param integral
     * @return
     */
    @PostMapping("/updateIntegral")
    public ResultData updateIntegral(Integral integral) {
        return new ResultData(RespStatusInfo.OK, integralService.updateIntegral(integral));
    }

    /**
     * 删除积分商城信息
     *
     * @param integralId
     * @return
     */
    @PostMapping("/deleteIntegral")
    public ResultData deleteIntegral(Integer integralId) {
        return new ResultData(RespStatusInfo.OK, integralService.deleteIntegral(integralId));
    }

}
